package com.lolan.training.common.entity;

import com.lolan.training.common.constants.ErrorCode;
import lombok.Data;

/**
 * 数据统一响应信息封装
 */
@Data
public class ResponseObject {

	// 返回操作编号
	private int errorCode;

	// 返回操作信息
	private String message;

	// 返回操作数据
	private Object data;

	/**
	 * 返回成功对象
	 *
	 * @param data
	 * @return
	 */
	public static ResponseObject getSuccessResponse(Object data) {
		ResponseObject ro = new ResponseObject();
		ro.data = data;
		ro.errorCode = ErrorCode.SUCCESS.getCode();
		return ro;
	}

	/**
	 * 返回失败对象, 空数据体
	 *
	 * @param errorCode
	 * @return
	 */
	public static ResponseObject getErrorResponse(ErrorCode errorCode) {
		ResponseObject ro = new ResponseObject();
		ro.data = null;
		ro.errorCode = errorCode.getCode();
		ro.message = errorCode.getMessage();
		return ro;
	}

	/**
	 * 返回失败对象, 有失败数据体
	 *
	 * @param data
	 * @param errorCode
	 * @return
	 */
	public static ResponseObject getErrorResponse(Object data, ErrorCode errorCode) {
		ResponseObject ro = new ResponseObject();
		ro.data = data;
		ro.errorCode = errorCode.getCode();
		ro.message = errorCode.getMessage();
		return ro;
	}

}
